/** *
 * @desc    智能侦测有关配置
 * @author  邓清波
 * @date    2022/11/18
 *
 * ***/

import store from '@/store'
import { computed } from 'vue'
import dayjs from 'dayjs'
import { getDict } from '@/core/dictionaries'

const roadType = computed(() => store.state.config.roadType)

const jtsgDict = { name: '交通事故', eventType: 1, value: 'TAA1', eventAttribute: 1 }
const clgzDict = { name: '车辆故障', eventType: 2, value: 'FA', eventAttribute: 2 }
const sgyhDict = { name: '施工养护', eventType: 5, value: 'JEA1', eventAttribute: 2 }
const eltqDict = { name: '恶劣天气', eventType: 2, value: 'TBA1', eventAttribute: 1 }

const dzzhDict = { name: '地质灾害', eventType: 3, value: 'TCA1', eventAttribute: 1 }
const tfqtDict = { name: '突发其他', eventType: 4, value: 'TDA1', eventAttribute: 1 }

const zawDict = { name: '障碍物', eventType: 5, value: 'HA', eventAttribute: 5 }
const dllDict = { name: '大流量', eventType: 6, value: 'EA', eventAttribute: 6 }

// 高速
const gsJtsg = { name: '交通事故', eventType: 1, value: 'TAB1' }
const gsClgz = { name: '车辆故障', eventType: 2, value: 'TAB2' }
const gsSgyh = { name: '施工养护', eventType: 3, value: 'JEB1' }
const gsEltq = { name: '恶劣天气', eventType: 4, value: 'TBB1' }
const gsZaw = { name: '障碍物', eventType: 5, value: 'TDB2' }
const gsDll = { name: '大流量', eventType: 6, value: 'TDB1' }
const confirmDisabeld = true

/**
 * 拼接位置信息
 *
 * **/
function concatPosition(record = {}) {
  const positionInfo = record.positionInfo || {}
  const startStake = record.startStakeK ? ' K' + record.startStakeM : ''
  const endStake = record.endStakeK ? '-K' + record.endStakeM : ''
  return (record.roadNum || ' ') + (startStake || '') + (endStake || '')
}

// 智能侦测信息确认 start   同apifox 确认类型
const confirmType = 1 // 确认
const misstateType = 3 // 误报
const ignoreType = 4 // 忽略
// 智能侦测信息确认 end

export default [
  {
    title: 'AI监测', // 智能侦测标题
    qsCode: 'MENU:AIJC', // qscode 动态渲染tab匹配字段
    key: 'aijc', // 事件key 后续改为字典
    type: 1, // 事件类型 后续改为字典
    rowOperatesText: '核实', // 行操作文本  核实,忽略,误报都是一个函数 通过字符串判断执行什么
    // 智能侦测详情start
    // 转换事件      confirmDisabeld禁用确认事件
    tranformEvent:
      roadType.value === 2
        ? [jtsgDict, { ...sgyhDict, confirmDisabeld }, { ...eltqDict, confirmDisabeld }, {}]
        : [
            gsJtsg,
            gsClgz,
            { ...gsSgyh, confirmDisabeld },
            { ...gsZaw, confirmDisabeld },
            { ...gsEltq, confirmDisabeld },
            { ...gsDll, confirmDisabeld },
            {},
            {}
          ],
    showInput: true, // 显示输入框
    operates: [
      // 详情底部操作按钮  通过operateType 判断执行什么函数   关联事件没有 operateType   同apifox 确认类型(1:确认;2:误报;3:忽略;)
      { text: '确认事件', key: 'confirm', className: 'confirm', operateType: confirmType },
      { text: '关联事件', key: 'connect', className: 'connect' },
      { text: '误报', key: 'misstate', className: 'misstate', operateType: misstateType },
      { text: '忽略', key: 'ignore', className: 'ignore', operateType: ignoreType }
    ],
    // 详情列表 一般的文本都是此处处理   [key]  详情检索路径， 如有render函数  render优先级大于key
    detailList: [
      {
        text: '告警类型',
        key: 'alertType',
        render(i) {
          if (!i.alertType) return ''
          return getDict('ZNZC-AI-EVENTTYPE', i.alertType, '') || i.alertType
        }
      },
      { text: '告警时间', key: 'monitorTime' },
      {
        text: '事件级别',
        render(record) {
          if (!record.eventLevel) return ''
          return getDict('ZNZC-LEVEL', record.eventLevel, '') || ''
        }
      },
      {
        text: '相机位置',
        key: 'hoverText'
      },
      {
        text: '数据来源',
        key: 'dataSource',
        render(record) {
          if (!record.dataSource) return ''
          return getDict('ZNZC-SJLY', record.dataSource, '') || record.dataSource
        }
      }
    ]
    // 智能侦测详情end
  },
  {
    title: '交通态势',
    key: 'jtts',
    qsCode: 'MENU:JTTS',
    type: 2,
    rowOperatesText: '核实',
    tranformEvent:
      roadType.value === 2
        ? [jtsgDict, { ...sgyhDict, confirmDisabeld }, { ...eltqDict, confirmDisabeld }, {}]
        : [
            gsJtsg,
            gsClgz,
            { ...gsSgyh, confirmDisabeld },
            { ...gsZaw, confirmDisabeld },
            { ...gsEltq, confirmDisabeld },
            gsDll,
            {},
            {}
          ],

    showInput: true,
    showSelect: true,
    operates: [
      { text: '确认事件', key: 'confirm', className: 'confirm', operateType: confirmType },
      { text: '关联事件', key: 'connect', className: 'connect' },
      { text: '误报', key: 'misstate', className: 'misstate', operateType: misstateType },
      { text: '忽略', key: 'ignore', className: 'ignore', operateType: ignoreType }
    ],
    detailList: [
      { text: '告警时间', key: 'monitorTime' },
      {
        text: '事件级别',
        render(record) {
          if (!record.eventLevel) return ''
          return getDict('ZNZC-LEVEL', record.eventLevel, '') || ''
        }
      },
      { text: '拥堵程度', key: 'infoType' },
      { text: '位置', key: 'hoverText' },
      {
        text: '拥堵长度',
        render(record) {
          return record.jamDistance ? record.jamDistance + 'm' : ''
        }
      }
    ]
  },
  {
    title: '协同上报',
    qsCode: 'MENU:XTSB',
    key: 'xtsb',
    type: 3,
    rowOperatesText: '核实',
    tranformEvent: roadType.value === 2 ? [jtsgDict, {}, {}, {}] : [gsJtsg, gsClgz, gsZaw, {}],
    showInput: true,
    operates: [
      { text: '确认事件', key: 'confirm', className: 'confirm', operateType: confirmType },
      { text: '关联事件', key: 'connect', className: 'connect' },
      { text: '误报', key: 'misstate', className: 'misstate', operateType: misstateType },
      { text: '忽略', key: 'ignore', className: 'ignore', operateType: ignoreType }
    ],
    detailList: [
      {
        text: '类型',
        key: 'alertType',
        render(i) {
          if (!i.alertType) return ''
          return getDict('ZNZC-AI-EVENTTYPE', i.alertType, '') || ''
        }
      },
      {
        text: '时间',
        render(record) {
          if (!record.monitorTime) return ''
          return dayjs(record.monitorTime).format('YYYY-MM-DD HH:mm:ss')
        }
      },
      {
        text: '事件级别',
        render(record) {
          if (!record.eventLevel) return ''
          return getDict('ZNZC-LEVEL', record.eventLevel, '') || ''
        }
      },
      { text: '位置', key: 'hoverText' },
      {
        text: '数据来源',
        key: 'dataSource',
        render(record) {
          if (!record.dataSource) return ''
          return getDict('ZNZC-SJLY', record.dataSource, '') || record.dataSource || ''
        }
      },
      { text: '当事人手机', key: 'partyPhone' },
      { text: '上报人手机', key: 'escPhone' },
      { text: '事件描述', key: 'describe' }
      // { text: '图片', key: 'data.images.length' }
    ] // [?]]
  },
  {
    title: '客服工单',
    key: 'kfgd',
    qsCode: 'MENU:KFGD',

    type: 1,
    rowOperatesText: '核实',
    tranformEvent: roadType.value === 2 ? [jtsgDict, zawDict] : [clgzDict],
    showInput: true,
    operates: [
      { text: '确认事件', key: 'confirm', className: 'confirm', operateType: confirmType },
      { text: '关联事件', key: 'connect', className: 'connect' },
      { text: '误报', key: 'misstate', className: 'misstate', operateType: misstateType },
      { text: '忽略', key: 'ignore', className: 'ignore', operateType: ignoreType }
    ],

    detailList: [
      { text: '工单类型', key: 'alarmType' },
      { text: '工单时间', key: 'monitorTime' },
      {
        text: '位置',
        render(record) {
          return '123'
        }
      },
      { text: '当事人姓名', key: 'partyName' },
      { text: '当事人手机', key: 'partyPhone' },
      { text: '车牌号码', key: 'plateNo' },
      { text: '工单内容', key: 'workingContend' }
    ]
  },
  {
    title: '相邻路段',
    qsCode: 'MENU:XLLD',
    key: 'xlld',
    type: 4,
    rowOperatesText: '忽略'
  },
  {
    title: '气象预警',
    qsCode: 'MENU:QXYJ',
    key: 'qxyj',
    type: 5,

    rowOperatesText: '核实',
    showInput: true,
    operates: [
      { text: '确认事件', key: 'confirm', className: 'confirm', operateType: confirmType },
      { text: '关联事件', key: 'connect', className: 'connect' },
      { text: '误报', key: 'misstate', className: 'misstate', operateType: misstateType },
      { text: '忽略', key: 'ignore', className: 'ignore', operateType: ignoreType }
    ],
    detailList: [
      { text: '告警类型', key: 'alarmType' },
      { text: '告警时间', key: 'monitorTime' },
      { text: '事件级别', key: 'detectionLevel' },
      { text: '道路能见度', key: 'visibility' },
      { text: '降雨量', key: 'precipitation' },
      { text: '湿度', key: 'humidity' },
      { text: '瞬时级大风', key: 'gale' },
      { text: '位置', key: 'hoverText' },
      { text: '长度', key: 'length' },
      { text: '影响路段', key: 'influenceRoad' },
      { text: '发展趋势', key: 'developmentTendency' }
    ]
  },
  {
    title: '重点车辆',
    qsCode: 'MENU:ZDCL',
    key: 'zdcl',
    type: 6,

    rowOperatesText: '核实',
    operates: [
      { text: '误报', key: 'misstate', className: 'misstate', operateType: misstateType },
      { text: '忽略', key: 'ignore', className: 'ignore', operateType: ignoreType }
    ],
    detailList: [
      { text: '类型', key: 'alarmType' },
      { text: '时间', key: 'monitorTime' },
      { text: '事件级别', key: 'detectionLevel' },
      { text: '当前位置', key: 'hoverText' },
      { text: '当事人手机', key: 'partyPhone' },
      { text: '入口', key: 'entry' }
    ]
  },

  {
    title: '桥梁健康',
    qsCode: 'MENU:QLJK',
    key: 'qljk',
    type: 7,
    rowOperatesText: '查看',
    operates: [{ text: '忽略', key: 'ignore', className: 'ignore', operateType: ignoreType }],
    detailList: [
      { text: '时间', key: 'alarmType' },
      { text: '事件级别', key: 'detectionLevel' },
      { text: '路线编码', key: 'roadNum' },
      { text: '中心桩号', key: 'centerPileNo' },
      { text: '桥梁编码', key: 'bridgeCode' },
      { text: '桥梁名称', key: 'bridgeName' },
      { text: '桥梁分类', key: 'bridgeType' },
      { text: '桥梁状况', key: 'abnormalCondition' },
      { text: '异常情况', key: 'unusualCondition' }
    ]
  },

  {
    title: '第三方', // 智能侦测标题
    qsCode: 'MENU:DSF',
    key: 'dsf', // 事件key 后续改为字典
    type: 9,
    rowOperatesText: '核实', // 行操作文本  核实,忽略,误报都是一个函数 通过字符串判断执行什么
    // 转换事件
    tranformEvent: [jtsgDict, dzzhDict, eltqDict, tfqtDict],
    showInput: true,
    operates: [
      // 详情底部操作按钮  通过operateType 判断执行什么函数   关联事件没有 operateType   同apifox 确认类型(1:确认;2:误报;3:忽略;)
      { text: '确认事件', key: 'confirm', className: 'confirm', operateType: confirmType },
      { text: '关联事件', key: 'connect', className: 'connect' },
      { text: '误报', key: 'misstate', className: 'misstate', operateType: misstateType },
      { text: '忽略', key: 'ignore', className: 'ignore', operateType: ignoreType }
    ],
    // 详情列表 一般的文本都是此处处理   [key]  详情检索路径， 如有render函数  render优先级大于key
    detailList: [
      // {
      //   text: '事件级别',
      //   render(record) {
      //     if (!record.eventLevel) return ''
      //     return getDict('ZNZC-LEVEL', record.eventLevel, '') || ''
      //   }
      // },
      {
        text: '事件发生路线',
        key: 'roadNum'
      },
      {
        text: '事件发生桩号',
        render(record) {
          const startStakeK = record.startStakeK ? 'k' + record.startStakeK : ''
          const startStakeM = record.startStakeM || ''
          return `${startStakeK}+${startStakeM}`
        }
      },
      {
        text: '联系人',
        key: 'linkman'
      },
      {
        text: '联系人电话',
        key: 'linkmanTel'
      },
      {
        text: '事件描述',
        key: 'eventType'
      }
    ]
    // 智能侦测详情end
  }
]

export { confirmType, misstateType, ignoreType }
